package svc

import (
	"generate_grom_mode_and_dao/common/dblink"
	"generate_grom_mode_and_dao/service/genertategrom/api/internal/config"
	"generate_grom_mode_and_dao/service/genertategrom/api/model"
	"gorm.io/gorm"
)

type ServiceContext struct {
	Config         config.Config
	EngineDb       *gorm.DB
	TableDao       model.TableDao
	TableFieldsDao model.TableFieldsDao
	DatabaseDao    model.DatabaseDao
}

func NewServiceContext(c config.Config) *ServiceContext {
	commonDb := dblink.NewConnectCommon("")
	db, err := commonDb.MysqlGenerateGorm(c.MysqlGenerateGorm.DataSource, "")
	if nil != err {
		panic("初始化MysqlGenerateGorm数据库失败: " + err.Error())
	}
	return &ServiceContext{
		Config:         c,
		EngineDb:       db,
		TableDao:       model.NewTableDao(db),
		TableFieldsDao: model.NewTableFieldsDao(db),
		DatabaseDao:    model.NewDatabaseDao(db),
	}
}
